/**
 * 
 */
package com.htht.smartschool.action.exam;

import java.util.List;

import com.google.gson.reflect.TypeToken;
import com.htht.smartschool.action.baseaction.BaseAction;
import com.htht.smartschool.common.model.ParamData;
import com.htht.smartschool.common.servlet.DataContainer;
import com.htht.smartschool.model.bigexam.BigExamBean;
import com.htht.smartschool.model.bigexam.BigExamCourse;
import com.htht.smartschool.model.bigexam.ExamResult;
import com.htht.smartschool.model.bigexam.UserStudent;
import com.htht.smartschool.model.card.TPhonebook;
import com.htht.smartschool.service.bigexam.BigExamService;
import com.htht.smartschool.service.exam.UpdateResultService;
import com.htht.smartschool.util.system.GsonUtils;

/**
 * @author 
 *
 */
public class ExamAction extends BaseAction {

	/**
	 * 
	 */
	@Override
	public boolean processData(DataContainer obj, ParamData pd) {
		UpdateResultService updateResultService = new UpdateResultService();
		boolean flag = false;
		BigExamBean big =null;
		try {
			big = (BigExamBean) GsonUtils.getInstance().fromJson(pd.getData(), BigExamBean.class);
		} catch (Exception e) {
			
		}
		if(pd.getCmd().equalsIgnoreCase("getExamsByType")){//查询校级考试的列表
			List<BigExamBean> bigExamBeanList = updateResultService.getExamsByType(big);
			if(bigExamBeanList.size() > 0){
				flag = true;
				obj.setData(bigExamBeanList);
			}else{
				obj.setData("查询失败");
			}
			
			
		}else if(pd.getCmd().equalsIgnoreCase("getBigExamCourses")){//查询科目列表
			BigExamBean bigExamBean = GsonUtils.getInstance().gson.fromJson(pd.getData(),BigExamBean.class);
			List<BigExamCourse> list = updateResultService.getBigExamCourses(bigExamBean);
			if(list!=null&&list.size()>0){
				flag = true;
				obj.setData(list);
			}else{
				obj.setData("查询失败");
			}
			
			
		}else if(pd.getCmd().equalsIgnoreCase("getScoreList")){//获取学生成绩列表
			BigExamCourse bigExamCourse = GsonUtils.getInstance().gson.fromJson(pd.getData(),BigExamCourse.class);
			List<ExamResult>  result = updateResultService.getScoreList(bigExamCourse);
			if(result.size() > 0){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("查询失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("updateScore")){//修改学生成绩
			ExamResult examResult = GsonUtils.getInstance().gson.fromJson(pd.getData(),ExamResult.class);
			boolean result = updateResultService.updateScore(examResult);
			if(result){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("修改失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getTotalScoreList")){//获取校总榜
			BigExamBean bigExamBean = GsonUtils.getInstance().gson.fromJson(pd.getData(),BigExamBean.class);
			List<ExamResult>  result = updateResultService.getTotalScoreList(bigExamBean);
			if(result.size() > 0){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("查询失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getOneScore")){//获取一个学生的成绩
			ExamResult examResult = GsonUtils.getInstance().gson.fromJson(pd.getData(),ExamResult.class);
			List<ExamResult>  result = updateResultService.getOneScore(examResult);
			if(result.size() > 0){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("查询失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getExamsClass")){//获取小测验列表
			BigExamBean bigExamBean = GsonUtils.getInstance().gson.fromJson(pd.getData(),BigExamBean.class);
			List<BigExamBean>  result = updateResultService.getExamsClass(bigExamBean);
			if(result.size() > 0){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("查询失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getResultList")){//获取小测验排名表
			BigExamBean bigExamBean = GsonUtils.getInstance().gson.fromJson(pd.getData(),BigExamBean.class);
			List<ExamResult>  result = updateResultService.getResultList(bigExamBean);
			if(result.size() > 0){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("查询失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("updateExamScore")){//修改小测验成绩
			ExamResult examResult = GsonUtils.getInstance().gson.fromJson(pd.getData(),ExamResult.class);
			boolean  result = updateResultService.updateExamScore(examResult);
			if(result){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("修改失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getChildsExams")){//查询孩子的考试科目
			UserStudent userStudent = GsonUtils.getInstance().gson.fromJson(pd.getData(),UserStudent.class);
			List<BigExamBean>  result = updateResultService.getChildsExams(userStudent);
			if(result.size()>0){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("查询失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getChildScore")){//查询孩子一次考试的各科成绩、总分、排名
			BigExamBean bigExamBean = GsonUtils.getInstance().gson.fromJson(pd.getData(),BigExamBean.class);
			List<ExamResult>  result = updateResultService.getChildScore(bigExamBean);
			if(result.size()>0){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("查询失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getChileTests")){//家长查询小测验考试列表
			UserStudent userStudent = GsonUtils.getInstance().gson.fromJson(pd.getData(),UserStudent.class);
			List<BigExamBean>  result = updateResultService.getChileTests(userStudent);
			if(result.size()>0){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("查询失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getChildTestScore")){//家长查询学生一次小测验的成绩
			BigExamBean bigExamBean = GsonUtils.getInstance().gson.fromJson(pd.getData(),BigExamBean.class);
			ExamResult examResult= updateResultService.getChildTestScore(bigExamBean);
			if(examResult!=null){
				flag = true;
				obj.setData(examResult);
			}else{
				obj.setData("查询失败");
			}
		}
		
		
		
		
		return flag;
	}

}
